<?

class Qi_Util_Methodify
{
	public $result = null;

	public function __construct($context)
	{
		$this->result = $context;
	}

	public function __call($name, $params = array())
	{
		$params = array_merge(array($this->result), $params);
		return $this->_run($name, $params);
	}

	public function _run($name, $params)
	{
		$r = new ReflectionFunction($name);
		$context = $r->invokeArgs($params);
		return new Qi_Util_Methodify($context);
	}

	public function __get($name)
	{
		return $this->$name();
	}

	public static function init($context)
	{
		return new Qi_Util_Methodify($context);
	}

	public function __toString()
	{
		return (string)$this->result;
	}

	public function explode($delimiter = " ", $limit = null)
	{
		$args = array($delimiter, $this->result);
		if ($limit !== null) $args[] = $limit;
		return $this->_run(__FUNCTION__, $args);
	}
}

$str = " AbcdEfghIjklm nOpqrstUvwxyz ";
Qi_Util_Methodify::init($str)->explode->array_reverse->print_r;
//echo Qi_Util_Methodify::init($str)->trim();
//echo "\n";
//Qi_Util_Methodify::init($str)->trim->strrev->strtolower->explode("m")->var_dump;

Qi_Util_Methodify::init($str)->strlen->number_format(2, ",", ".")->var_dump;
?>